package kr.hkit.powerjava.chther12;

import java.util.Arrays;
import java.util.Comparator;
class student {
	private String stdName;
	private double gpa;
	public String getStdName() {
		return stdName;
	}
	public student(String stdName, double gpa) {
		this.stdName = stdName;
		this.gpa = gpa;
	}
	public void setStdName(String stdName) {
		this.stdName = stdName;
	}
	public double getGpa() {
		return gpa;
	}
	public void setGpa(double gpa) {
		this.gpa = gpa;
	}
	@Override
	public String toString() {
		return String.format("student [stdName=%s, gpa=%s]", stdName, gpa);
	}
//	@Override
//	public int compareTo(student o) {
//		// TODO Auto-generated method stub
//		return (int)(this.gpa-o.gpa);
//	}
}
public class SortTest {
	public static void main(String[] args) {
		int[] arr= {5,6,7,8,1,2,3,4};
		
		prnarr(arr);
		Arrays.sort(arr);
		prnarr(arr);
		
		student[] arrstd = new student[4];
		arrstd[0]= new student("홍길동", 3.39);
		arrstd[1]= new student("황감동", 1.39);
		arrstd[2] =new student("허김동", 2.39);
		arrstd[3] =new student("김김동", 0.39);
//		prnArr(arrstd);
		
//		Arrays.sort(arrstd);
		Comparator<student> comp = new Comparator<student>() {
			
			@Override
			public int compare(student o1, student o2) {
				// TODO Auto-generated method stub
				return o1.getStdName().hashCode()-o2.getStdName().hashCode();
			}
		};
		// ㅠㅕㅇ점순
		Comparator<student> comgpa = new Comparator<student>() {
			@Override
			public int compare(student o1, student o2) {
				// TODO Auto-generated method stub
				return (int)(o1.getGpa()-o2.getGpa());
			}
		};
		Arrays.sort(arrstd, comp);
		prnArr(arrstd);
		
		Arrays.sort(arrstd, comgpa);
		prnArr(arrstd);
		
		
	}

	private static void prnArr(student[] arrstd) {
		// TODO Auto-generated method stub
		for(student s : arrstd){
			System.out.println(s);
		}
		System.out.println();
	}

	private static void prnarr(int[] arr) {
		// TODO Auto-generated method stub
		for(int e:arr){
			System.out.printf("%2d",e);
		}
		System.out.println();
	}
}
